#!/usr/bin/env escript

main(Args) ->
    VerbosePred = fun(X) -> X =:= "-v" orelse X =:= "--verbose" end,
    Verbose = lists:any(VerbosePred, Args),
    ActualArgs =
        if
            Verbose ->
                lists:filter(fun(X) -> not VerbosePred(X) end, Args);
            true ->
                Args
        end,

    P = ftest:start(),
    lists:foreach(fun(X) -> ftest:add_file(P, X, " \t\n") end, ActualArgs),
    lists:foreach(fun(X) ->
                          if
                              Verbose ->
                                  io:format("~p ... ", [X]),
                                  io:format("~p~n", [ftest:wait_file(P, X, infinity)]);
                              true ->
                                  case ftest:wait_file(P, X, infinity) of
                                      ok ->
                                          ok;
                                      Error ->
                                          io:format("~p ... ~p~n", [X, Error])
                                  end
                          end
                  end, ActualArgs),
    {ok, Dict} = ftest:get_dict(P),
    ftest:print(Dict, Verbose),
    ok.
